package data_structure;

public class leetcode_0543 {
    public int diameterOfBinaryTree(TreeNode root) {
        int[] max=new int[1];
        search(root,max);
        return max[0];
    }
    public int search(TreeNode node,int[] max){
        int left=0;
        int right=0;
        if(node.left!=null){
            left=search(node.left,max)+1;
        }
        if(node.right!=null){
            right=search(node.right,max)+1;
        }
        max[0]=Math.max(max[0],left+right);
        return Math.max(left,right);
    }
}
